N Queens
Hard
Question
Given a square chessboard of n width and height, place n queens on the board such that they do not attack each other (a queen cannot be on the same line horizontally, vertically, or diagonally as another queen).
Return all possible solutions to the n queens problem.
Note: In our solution, "Q" indicates a queen while "." indicates an empty space.
Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
There are two distinct solutions to the 4-queens puzzle:
Input: n = 1
Output: [["Q"]]
There is a single solution to the 1-queen puzzle:
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
How many unique combinations should we return if given n = 2?
0
1
2
4
Take a moment to understand the problem and think of your approach before you start coding.